﻿/*
 * 作者：范虹霞
 * 功能描述：新增区块
 * 时间：2018-1-19
 * 修改人：
 * 修改时间：
 *
 */

using Common;
using DataBusiness;
using Entity;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using WHC.Framework.BaseUI;


namespace UI
{
    //区块
    public partial class frmArea : Form
    {

        public frmArea()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.txtName.Text.Trim() == "")
            {
                AppMethod.ShowWarning("区块名称不能为空");
                this.txtName.Focus();
                return;
            }
            else if(!AppMethod.IsNumber(txtExistingWells.Text))
            {
                AppMethod.ShowWarning("请输入整数");
                this.txtExistingWells.Focus();
                return;
            }
            else if(!AppMethod.IsNumberic(txtStart_Location.Text))
            {
                AppMethod.ShowWarning("请输入精确到小数点后两位的小数或整数");
                this.txtStart_Location.Focus();
                return;
            }
            else if (!AppMethod.IsNumberic(txtEndLocation.Text))
            {
                AppMethod.ShowWarning("请输入精确到小数点后两位的小数或整数");
                this.txtEndLocation.Focus();
                return;
            }
            else if (!AppMethod.IsNumberic(txtBlockArea.Text))
            {
                AppMethod.ShowWarning("请输入精确到小数点后两位的小数或整数");
                this.txtBlockArea.Focus();
                return;
            }
            else
            {
                ////读注册表中的内容
                //RegistryKey regKey;
                //regKey = Registry.CurrentUser.OpenSubKey(AppPara.Account_RegistryKey);
                //string ReservoirType = string.Empty;
                //string ExploitStyle = string.Empty;
                //if (regKey != null)
                //{
                //    if (regKey.GetValue("ReservoirType") != null)
                //        ReservoirType = (string)regKey.GetValue("ReservoirType");
                //    if (regKey.GetValue("ExploitStyle") != null)
                //        ExploitStyle = (string)regKey.GetValue("ExploitStyle");
                //}

                //cbReservoirType.Properties.Items.Add(ReservoirType);
                //CbExploitStyle.Properties.Items.Add(ExploitStyle);
                ////写入注册表
                //regKey = Registry.CurrentUser.CreateSubKey(AppPara.Account_RegistryKey);
                //regKey.SetValue("ReservoirType", cbReservoirType.Text);
                //regKey.SetValue("ExploitStyle", CbExploitStyle.Text);
                //regKey.Close();
                try
                {
                    tb_AreaModel model = new tb_AreaModel();
                    model.Name = txtName.Text;
                    model.ReservoirType = cbReservoirType.Text;
                    model.ExploitStyle = CbExploitStyle.Text;
                    model.AcidType = rgAcidType.Text;
                    model.ExplorationDate = Convert.ToDateTime(DEExplorationDate.Text);
                    model.ExploitDate = Convert.ToDateTime(DEExplorationDate.Text);
                    model.ExistingWells = Convert.ToInt16(txtExistingWells.Text);
                    model.BlockLocation = txtStart_Location.Text;
                    model.BlockArea = Convert.ToDecimal(txtBlockArea.Text);
                    model.Start_Location = Convert.ToDecimal(txtStart_Location.Text);
                    model.EndLocation = Convert.ToDecimal(txtEndLocation.Text);
                    string i = AreaBLL.AddArea(model);
                    if (i == "exist")
                    {
                        AppMethod.ShowWarning("该名称已经存在");
                        txtName.Focus();
                        return;
                    }
                    else if (i == "1")
                    {                        
                        MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("保存失败", "提示", MessageBoxButtons.OKCancel);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
    }
}
